<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #msg{width:400px;height:200px;border: solid 1px black;}
    </style>
</head>
<body>
    <textarea id="txt1"></textarea>
    <input type="button" id="btn1" value="敏感词过滤">
    <input type="button" id="btn2" value="翻转字符串">
    <input type="button" id="btn3" value="是否是回文字符串">
</body>
        <script>
             // 1. 敏感词过滤
    //     - 敏感词库自己设定
    var arr = ["abc", "你好", "哈哈", "hello"];
    var txt1 = document.getElementById("txt1")
    var btn1 = document.getElementById("btn1")
    var msg = document.getElementById("msg")

    btn1.onclick = function(){
        var str = txt1.value;
        for(var j=0;j<str.length;j++){
            for(var i=0;i<arr.length;i++){
                str = str.replace(arr[i], "***");
            }
        }
        msg.innerHTML = str;
    }
    


    // 2. 翻转字符串
    var btn2 = document.getElementById("btn2")
    btn2.onclick = function(){
        var str = txt1.value;
        str = str.split("").reverse().join("");

        msg.innerHTML = str;
    }




    // 3. 判断字符串是否是回文字符串
    var btn3 = document.getElementById("btn3")
    btn3.onclick = function(){
        var str = txt1.value;
        msg.innerHTML = isH(str);
    }

    function isH(str){

        var c = str.length%2 ? parseInt(str.length/2) : str.length/2;
        for(var i=0;i<c;i++){
            if(str[i] !== str[str.length-1-i]){
                return false;
            }
        }
        return true;
    }

        </script>
</html>